home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / init.d / ttdnsd < prev    next >
Encoding:
Text File  |  2013-01-10  |  4.0 KB  |  157 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          ttdnsd
  4. # Required-Start:    $remote_fs $syslog tor
  5. # Required-Stop:     $remote_fs $syslog tor
  6. # Default-Start:
  7. # Default-Stop:
  8. # Short-Description: Starts the Tor TCP DNS Daemon
  9. # Description:       This initscript runs a chrooted ttdnsd process
  10. #                    and it makes recursive TCP DNS requests through the Tor
  11. #                    network.
  12. ### END INIT INFO
  13.  
  14. # Author: Jacob Appelbaum <jacob@torproject.org>
  15.  
  16. # Do NOT "set -e"
  17.  
  18. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  19. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  20. DESC="ttdnsd daemon"
  21. NAME=ttdnsd
  22. DAEMON=/usr/sbin/$NAME
  23. PIDFILE=/var/lib/ttdnsd/pid
  24. SCRIPTNAME=/etc/init.d/$NAME
  25. DEFAULTSFILE=/etc/default/$NAME
  26. TSOCKS_CONF_FILE=tsocks.conf
  27. export TSOCKS_CONF_FILE
  28.  
  29. # Exit if the package is not installed
  30. [ -x "$DAEMON" ] || exit 0
  31.  
  32. # Read configuration variable file if it is present
  33. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  34.  
  35. # This will be overloaded by $DEFAULTS
  36. DAEMON_ARGS="-P $PIDFILE -f /etc/ttdnsd.conf $DEFAULTS"
  37.  
  38. # Load the VERBOSE setting and other rcS variables
  39. if [ -f /lib/init/vars.sh ];
  40. then
  41.     . /lib/init/vars.sh;
  42. else
  43.     echo "skipping load of vars.sh; not found";
  44. fi
  45.  
  46. # Define LSB log_* functions.
  47. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  48. . /lib/lsb/init-functions
  49.  
  50. #
  51. # Function that starts the daemon/service
  52. #
  53. do_start()
  54. {
  55.     # Return
  56.     #   0 if daemon has been started
  57.     #   1 if daemon was already running
  58.     #   2 if daemon could not be started
  59.     start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  60.         || return 1
  61.     start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  62.         $DAEMON_ARGS \
  63.         || return 2
  64.     # Add code here, if necessary, that waits for the process to be ready
  65.     # to handle requests from services started subsequently which depend
  66.     # on this one.  As a last resort, sleep for some time.
  67. }
  68.  
  69. #
  70. # Function that stops the daemon/service
  71. #
  72. do_stop()
  73. {
  74.     # Return
  75.     #   0 if daemon has been stopped
  76.     #   1 if daemon was already stopped
  77.     #   2 if daemon could not be stopped
  78.     #   other if a failure occurred
  79.     start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  80.     RETVAL="$?"
  81.     [ "$RETVAL" = 2 ] && return 2
  82.     # Wait for children to finish too if this is a daemon that forks
  83.     # and if the daemon is only ever run from this initscript.
  84.     # If the above conditions are not satisfied then add some other code
  85.     # that waits for the process to drop all resources that could be
  86.     # needed by services started subsequently.  A last resort is to
  87.     # sleep for some time.
  88.     start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  89.     [ "$?" = 2 ] && return 2
  90.     # Many daemons don't delete their pidfiles when they exit.
  91.     rm -f $PIDFILE
  92.     return "$RETVAL"
  93. }
  94.  
  95. #
  96. # Function that sends a SIGHUP to the daemon/service
  97. #
  98. do_reload() {
  99.     #
  100.     # If the daemon can reload its configuration without
  101.     # restarting (for example, when it is sent a SIGHUP),
  102.     # then implement that here.
  103.     #
  104.     start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  105.     return 0
  106. }
  107.  
  108. case "$1" in
  109.   start)
  110.     log_daemon_msg "Starting $DESC" "$NAME"
  111.     do_start
  112.     case "$?" in
  113.         0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  114.         2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  115.     esac
  116.     ;;
  117.   stop)
  118.     log_daemon_msg "Stopping $DESC" "$NAME"
  119.     do_stop
  120.     case "$?" in
  121.         0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  122.         2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  123.     esac
  124.     ;;
  125.   status)
  126.        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  127.        ;;
  128.   restart|force-reload)
  129.     #
  130.     # If the "reload" option is implemented then remove the
  131.     # 'force-reload' alias
  132.     #
  133.     log_daemon_msg "Restarting $DESC" "$NAME"
  134.     do_stop
  135.     case "$?" in
  136.       0|1)
  137.         do_start
  138.         case "$?" in
  139.             0) log_end_msg 0 ;;
  140.             1) log_end_msg 1 ;; # Old process is still running
  141.             *) log_end_msg 1 ;; # Failed to start
  142.         esac
  143.         ;;
  144.       *)
  145.           # Failed to stop
  146.         log_end_msg 1
  147.         ;;
  148.     esac
  149.     ;;
  150.   *)
  151.     echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  152.     exit 3
  153.     ;;
  154. esac
  155.  
  156. :
  157.